package com.wh.controller;

import com.alibaba.fastjson.JSONObject;
import com.wh.model.Employee;
import com.wh.model.PageRow;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by XuSir on 14-9-3.
 */
@Controller
@RequestMapping("api")
public class WorkController {
    @RequestMapping("test/{pageIndex}/{pageSize}")
    @ResponseBody
    public String getTestJson(@PathVariable("pageIndex") int pageIndex, @PathVariable("pageSize") int pageSize) {
        List<Employee> EmployeeList = new ArrayList<Employee>();
        int record=60;
        for (int i = (pageIndex - 1) * pageSize; i < pageIndex * pageSize&&i<record; i++) {
            Employee e = new Employee();
            e.setFirstName("名称" + i);
            e.setLastName("姓什么" + i);
            EmployeeList.add(e);
        }
        PageRow pageRow=new PageRow();
        pageRow.setData(EmployeeList);
        pageRow.setRecord(record);
        return JSONObject.toJSONString(pageRow);

    }
}
